﻿/**
* @author Alexander Rindo
* @project Flashview
* @version 0.4
* @purpose Manages keyboard input events
**/

package com.alexrindo.flashview.listeners 
{
	import com.alexrindo.flashview.image.ImageManager;
	import com.alexrindo.flashview.UI.ButtonManager;
	import flash.display.Stage;
	import flash.display.StageDisplayState;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	public class KeyListener
	{
		private var _stageObject:Stage
		private var _images:ImageManager
		private var _buttons:ButtonManager
		
		private static const INFO:int = 73
		private static const DOWNLOAD:int = 68
		private static const SHARE:int = 83
		
		public function KeyListener(stage:Stage) 
		{
			_stageObject = stage
			_images = ImageManager.getInstance()
			_buttons = ButtonManager.getInstance()
			setupListeners()
		}
		
		private function setupListeners():void
		{
			_stageObject.addEventListener(KeyboardEvent.KEY_DOWN, keyboardListener)
		}
		
		private function keyboardListener(e:KeyboardEvent):void
		{
			switch (e.keyCode)
			{
				case Keyboard.LEFT:
					_images.prevImage()
					if (_stageObject.displayState == StageDisplayState.FULL_SCREEN)
					{
						_images.checkSlideShow(false)
					}
					break;
				
				case Keyboard.RIGHT:
					_images.nextImage()
					if (_stageObject.displayState == StageDisplayState.FULL_SCREEN)
					{
						_images.checkSlideShow(false)
					}
					break;
				
				case Keyboard.UP:
					_images.zoom(0.2,true)
					break;

				case Keyboard.DOWN:
					_images.zoom(-0.2,true)
					break;

				case Keyboard.SPACE :
					_images.zoom(1,false)
					break;
					
				case KeyListener.INFO:
					_buttons.infoButton.play()
					_buttons.info_click()
					break
					
				case KeyListener.DOWNLOAD:
					_buttons.saveButton.play()
					_images.saveImage()
					break
					
				case KeyListener.SHARE:
					_buttons.shareButton.play()
					_buttons.share_click()
					break
			}
		}
	}
}